<?php
session_start();
$user_id = $_SESSION['userid'];
date_default_timezone_set('prc');


// 用户信息部分
if($user_id){
    $table = "user";
    $result = mysql_query("select * from $table where user_id ='$user_id'");

    while ($row = mysql_fetch_array($result)) {
        $user_name = $row['user_name'];
        $user_term = $row['user_term'];
        $department = $row['department'];
        $balance = $row['balance'];
        $password = $row['password'];
    }
}


// 日期列表部分
$todayDate = date('Y年m月d日',time()); //今天日期

$weekarray = array('日','一','二','三','四','五','六','日','一','二','三','四','五','六');
$weekDate = '星期'.$weekarray[date('w')]; //今天星期

$atarray = array('','早餐','午餐','晚餐');

function getWeek($unixTime=''){ // 获取明天星期
    $unixTime=is_numeric($unixTime)?$unixTime:time();
    $weekarray=array('日','一','二','三','四','五','六');
    return '星期'.$weekarray[date('w',$unixTime)];
}
function getWeekNum($unixTime){
    $weekarray=array('0','1','2','3','4','5','6');
    return $weekarray[date('w',$unixTime)];
}


//修改循环至9，原数字为7，满足一周,对应order.php 42行,因为是从1开始，所以要比前端大1
for($i=1;$i<10;$i++){
    $listDate[] = date('Y年m月d日',strtotime("+".$i." day")); // 明天日期
	
	$list_Date[] = date('d',strtotime("+".$i." day")); // 明天日期
	    $list_Date_m[] = number_format(date('m',strtotime("+".$i." day"))); // 明天月份
    $listWeek[] = getWeek(strtotime("+".$i." days"));
    $listWeekNum[] = getWeekNum(strtotime("+".$i." days"));
}



// 商品展示部分
$urlDate = $_GET["date"];
$urlWeek = $_GET["week"];
$urlAt = $_GET["at"];

if($urlAt){
    $productList = true;
}else{
    $productList = null;
}

$tableProduct = "product";
$resultPorduct = mysql_query("select * from $tableProduct where week ='$urlWeek' and at ='$urlAt'");
while ($row = mysql_fetch_array($resultPorduct)) {
    $product_name = $row['product_name'];
    $price = $row['price'];
}

$urlWeekStr = '星期'.$weekarray[$urlWeek];
$atStr = $atarray[$urlAt];




// 已订订单展示部分
$tableOrder = "orderlist";
/*$queryOrder = mysql_query("select count(nid) from $tableOrder where user_id='$user_id'");
$sumOrder = mysql_result($queryOrder, 0);*/

$sqlstr = "select * , sum(product_num) as product_numsum from $tableOrder where user_id='$user_id' group by product_name,order_date  order by nid desc";


$resultOrder = mysql_query($sqlstr);


while ($row = mysql_fetch_array($resultOrder)) {

    $product_name[] = $row['product_name'];
    $product_num[] = $row['product_num'];
    $product_numsum[] = $row['product_numsum'];
    $order_price[] = $row['order_price'];
    $order_date[] = $row['order_date'];
    $order_week[] = $row['order_week'];
    $order_at[] = $row['order_at'];
}
$sumOrder = count($product_name);

?>